
package ro.ase.catalog.jfreechart.style;

import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.labels.StandardCategoryToolTipGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;

import java.awt.*;
import java.text.DecimalFormat;


public class BarStyle {


    public static void styleDefault(JFreeChart chart){
        BarStyle.setBackground(chart);
                
    }
    

    public static void styleOne(JFreeChart chart){
        CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
        CategoryDataset dca = categoryplot.getDataset();

        chart.setBackgroundPaint(null);
        if(dca!=null){
            BarRenderer categoryitemrenderer = (BarRenderer)categoryplot.getRenderer();

            categoryitemrenderer.setBaseItemLabelGenerator(
                    new StandardCategoryItemLabelGenerator());
//
            categoryitemrenderer.setBaseItemLabelsVisible(true);
            //tooltip
            categoryplot.getRenderer().setBaseToolTipGenerator(new StandardCategoryToolTipGenerator("{0}={2}",new DecimalFormat()));

            for(int i = 0 ;i<dca.getRowCount();i++){
                int colorIdx = i % colors.length;
                categoryitemrenderer.setSeriesPaint(i, colors[colorIdx]);
            }
        }
        else{

            categoryplot.setNoDataMessage("NO DATA");
        }
    }


    public static void setBackground(JFreeChart chart){
        chart.setBackgroundPaint(null);
    }

    public static Paint colors[] = { 
        Color.decode("#88AACC"), Color.decode("#999933"),
        Color.decode("#666699"), Color.decode("#CC9933"),
        Color.decode("#006666"), Color.decode("#3399FF"),
        Color.decode("#993300"), Color.decode("#AAAA77"),
        Color.decode("#666666"), Color.decode("#FFCC66"),
        Color.decode("#6699CC"), Color.decode("#663366"),
        Color.decode("#9999CC"), Color.decode("#AAAAAA"),
        Color.decode("#669999"), Color.decode("#BBBB55"),
        Color.decode("#CC6600"), Color.decode("#9999FF"),
        Color.decode("#0066CC"), Color.decode("#99CCCC"),
        Color.decode("#999999"), Color.decode("#FFCC00"),
        Color.decode("#009999"), Color.decode("#99CC33"),
        Color.decode("#FF9900"), Color.decode("#999966"),
        Color.decode("#66CCCC"), Color.decode("#339966"),
        Color.decode("#CCCC33") 
    };
}
